package ml;

import java.util.List;
import java.util.Map.Entry;

import ml.features.FeatureExtractor;
import parser.ParserAnnotation;
import parser.ParserPipeline;

import corpus.SentPolarityCorpus;
import forum.ForumPost;

public class SequenceDataModel extends DataModel {
	int nbrWritten = 0;

	/**
	 * In HCRF there is one feature vector per feature per sample, instead of
	 * one feature vector per sample.
	 */
	public SequenceDataModel(String name, ParserPipeline pp, String[] labels) {
		super(name, pp, labels);
	}

	@Override
	public void classify(ForumPost post) throws Exception {
		throw new Error("The classification with HCRF is not yet implemented.");
	}

	@Override
	public void extractFeatures(SentPolarityCorpus spc) {
		for (Entry<String, String> e : spc.getCorpus().entrySet()) {
			ParserAnnotation pa = spc.getParsedPA(e.getKey(), pp);

			for (FeatureExtractor f : features) {
				List<Data>[] datas = f.extractSequence(pa, 0);
				for (List<Data> d : datas) {
					FeatureVector fv = new FeatureVector();
					fv.addSequence(d);
					fv.setLabel(labelIndex(e.getValue()));
					data.add(fv);
				}
			}
		}
	}
}
